# -*- coding: utf-8 -*-
from datetime import datetime, timedelta


class MyTime:
    def __init__(self, year: int, month: int, day: int, hour: int = 0, minute: int = 0, second: int = 0, time: datetime = None):
        """初始化 MyTime 对象"""
        self.year = year
        self.month = month
        self.day = day
        self.hour = hour
        self.minute = minute
        self.second = second
        self.current_day = f"{year:04d}{month:02d}{day:02d}"
        self.time = time

    @classmethod
    def of(cls, dt: datetime):
        return cls(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt)

    def get_time_str(self, format_str: str = "%Y-%m-%d %H:%M:%S") -> str:
        """获取格式化的时间字符串"""
        return datetime(self.year, self.month, self.day, self.hour, self.minute, self.second).strftime(format_str)

    def __str__(self) -> str:
        """返回时间的字符串表示"""
        return self.get_time_str()
